package com.ruoyi.web.controller.check;
import com.ruoyi.check.domain.SpotCheck;
import com.ruoyi.check.service.ISpotCheckService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 执法信息录入Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/check/spot")
public class SpotCheckController extends BaseController
{
    @Autowired
    private ISpotCheckService spotCheckService;

    /**
     * 查询执法信息录入列表
     */
    @PreAuthorize("@ss.hasPermi('check:spot:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpotCheck spotCheck)
    {
        startPage();
        List<SpotCheck> list = spotCheckService.selectSpotCheckList(spotCheck);
        return getDataTable(list);
    }

    /**
     * 导出执法信息录入列表
     */
    @PreAuthorize("@ss.hasPermi('check:spot:export')")
    @Log(title = "执法信息录入", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpotCheck spotCheck)
    {
        List<SpotCheck> list = spotCheckService.selectSpotCheckList(spotCheck);
        ExcelUtil<SpotCheck> util = new ExcelUtil<SpotCheck>(SpotCheck.class);
        return util.exportExcel(list, "执法信息录入数据");
    }

    /**
     * 获取执法信息录入详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:spot:query')")
    @GetMapping(value = "/{scId}")
    public AjaxResult getInfo(@PathVariable("scId") Long scId)
    {
        return AjaxResult.success(spotCheckService.selectSpotCheckById(scId));
    }

    /**
     * 新增执法信息录入
     */
    @PreAuthorize("@ss.hasPermi('check:spot:add')")
    @Log(title = "执法信息录入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpotCheck spotCheck)
    {
        return toAjax(spotCheckService.insertSpotCheck(spotCheck));
    }

    /**
     * 修改执法信息录入
     */
    @PreAuthorize("@ss.hasPermi('check:spot:edit')")
    @Log(title = "执法信息录入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpotCheck spotCheck)
    {
        return toAjax(spotCheckService.updateSpotCheck(spotCheck));
    }

    /**
     * 删除执法信息录入
     */
    @PreAuthorize("@ss.hasPermi('check:spot:remove')")
    @Log(title = "执法信息录入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scIds}")
    public AjaxResult remove(@PathVariable Long[] scIds)
    {
        return toAjax(spotCheckService.deleteSpotCheckByIds(scIds));
    }
}
